package com.mrbeard.greenbroswer.utils;

import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.provider.Settings;
import android.support.v4.content.ContextCompat;
import android.telephony.TelephonyManager;

import com.mrbeard.greenbroswer.entites.Device;

import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Collections;
import java.util.List;

/**
 * Created by 胡彬 on 2018/3/30.
 */
public class DeviceUtil {

    private Context context;
    private String version;
    private String imei;
    private String alias;
    private String osVersion;
    private String mac;

    public DeviceUtil(Context context) {
        this.context = context;
    }

    public Device getDevice() {

        //获取androidID
        version = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);

        //获取imei
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(context.TELEPHONY_SERVICE);
        imei = telephonyManager.getDeviceId();

        //获取serialNumber序列号
        mac = android.os.Build.SERIAL;


        //获取设备名称
        alias = android.os.Build.MODEL;

        //获取手机系统版本
        osVersion = android.os.Build.VERSION.RELEASE;
        osVersion = "android "+osVersion;


        if (version == null) {
            //如果为空，为其赋值defaultAndroidId
            version = "defaultAndroidId";
        }
        if (imei == null) {
            //如果为空，为其赋值defaultImei
            imei = "defaultImei";
        }
        if(alias == null){
            alias = "defaultAlias";
        }
        if(osVersion == null){
            osVersion = "defaultOsVsion";
        }
        if(mac == null){
            mac = "defaultMac";
        }

        Device device = new Device();
        device.setAlias(alias);
        device.setImei(imei);
        device.setMac(mac);
        device.setOsVersion(osVersion);
        device.setVersion(version);

        return device;
    }
}